package com.hys.controller;

import com.hys.pojo.entity.PageBean;
import com.hys.pojo.entity.ResponseResult;
import com.hys.pojo.good.Brand;
import com.hys.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {
    /*品牌控制器  包含品牌的查询 添加  删除 更新*/
    /*注入业务类 */
    @Autowired
    private BrandService brandService;

    /*获取所有品牌数据 */
    @RequestMapping("/getAllBrand")
    public List<Brand> getAllBrand(){
        /*调用业务层,获取所有品牌数据*/

        List<Brand> allBrand = brandService.getAllBrand();

        return allBrand;
    }

    @RequestMapping("/getPageBrand")
    public ResponseResult getPageBrand(Integer curPage,Integer pageSize, @RequestBody Brand searchBrand){
        /*调用业务层, 做分页的查询  返回一个PageBean*/
        PageBean pageBean = brandService.getPageBrand(curPage,pageSize,searchBrand);

        return new ResponseResult(true,pageBean);
    }

    @RequestMapping("/add")
    public ResponseResult add(@RequestBody Brand brand){
        brandService.addBrand(brand);
        return new ResponseResult(true,"保存成功");
    }

    @RequestMapping("/update")
    public ResponseResult update(@RequestBody Brand brand){
        brandService.updateBrand(brand);
        return new ResponseResult(true,"更新成功");
    }

    @RequestMapping("/deleteBrand")
    public ResponseResult deleteBrand(@RequestBody Long[] ids){
        brandService.deleteBrand(ids);
        return new ResponseResult(true,"删除成功");
    }

}
